package com.lijie.ljblog.config;

import com.lijie.ljblog.socketAPI.MatchAPI;
import com.lijie.ljblog.socketAPI.PVEGameAPI;
import com.lijie.ljblog.socketAPI.PVPGameAPI;
import com.lijie.ljblog.socketAPI.TextWebSocketAPI;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import javax.annotation.Resource;

/**
 * @Description
 * @Author lijie
 * @Date 2022/8/24 9:51
 **/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Resource
    TextWebSocketAPI textWebSocketAPI;

    @Resource
    MatchAPI matchAPI;
    @Resource
    PVEGameAPI pveGameAPI;
    @Resource
    PVPGameAPI pvpGameAPI;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //这个方法可以将一个消息处理器和一个路由关联上，访问这个路由后将使用testAPI的方法进行消息处理
        registry.addHandler(textWebSocketAPI,"test").setAllowedOrigins("*");
        registry.addHandler(matchAPI,"findMatch").setAllowedOrigins("*");
        registry.addHandler(pveGameAPI,"pveGame").setAllowedOrigins("*");
        registry.addHandler(pvpGameAPI,"pvpGame").setAllowedOrigins("*");
    }
}
